package top.toptimus.dto.material;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * 订单选择索引
 */
@NoArgsConstructor
@Data
@AllArgsConstructor
public class MaterialOrderIndexDTO {
    private String materialId;
    private String materialNameCn;
    private String materialCode;
    private String materialComposition;
    private double fabricQuanlity;  //  库存数量
    private double unitPrice;   //  库存加权平均价格

    public MaterialOrderIndexDTO(Map<String, Object> stringObjectMap) {
        try {
            this.materialId = stringObjectMap.get("MATERIAL_ID").toString();
        } catch (Exception ignored) {
        }
        try {
            this.materialNameCn = stringObjectMap.get("MATERIAL_NAME_CN").toString();
        } catch (Exception ignored) {
        }
        try {
            this.materialCode = stringObjectMap.get("MATERIAL_CODE").toString();
        } catch (Exception ignored) {
        }
        try {
            this.materialComposition = stringObjectMap.get("MATERIAL_COMPOSITION").toString();
        } catch (Exception ignored) {
        }
    }

    public MaterialOrderIndexDTO build(
            double fabricQuanlity,
            double unitPrice
    ) {
        this.fabricQuanlity = fabricQuanlity;
        this.unitPrice = unitPrice;
        return this;
    }
}
